﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using Microsoft.Practices.Unity;
using Condimar.Entities;
using Condimar.BussinesLogic;

namespace Condimar.UI
{
    public partial class FrmCliente : Form
    {

        [Dependency]
        public IClienteBL clienteBL { get; set; }
        public FrmCliente()
        {
            InitializeComponent();
            this.BuildUp();
        }

        private void label1_Click(object sender, EventArgs e)
        {

        }

        private void checkBox1_CheckedChanged(object sender, EventArgs e)
        {

        }

        private void checkBox2_CheckedChanged(object sender, EventArgs e)
        {

        }

        private void pictureBox1_Click(object sender, EventArgs e)
        {

        }

        private void FrmCliente_Load(object sender, EventArgs e)
        {
            clienteBindingSource.DataSource = clienteBL.GetAllFromClientes();
        }

        private void button2_Click(object sender, EventArgs e)
        {
            FrmMttoClente frm = new FrmMttoClente();
            frm.Nuevo();
            frm.ShowDialog();
        }

        private void clienteDataGridView_CellContentClick(object sender, DataGridViewCellEventArgs e)
        {

        }
        public Cliente CurrentCliente { get; set; }
        private void button3_Click(object sender, EventArgs e)
        {
            Cliente currentCliente = clienteBindingSource.Current as Cliente;
            if (currentCliente != null)
            {
                FrmMttoClente frmmttocliente = new FrmMttoClente();
                frmmttocliente.CurrentCliente = currentCliente;
                frmmttocliente.Editar();
                frmmttocliente.ShowDialog();
            }
            else
            {
                MessageBox.Show("Mensaje", "Seleccione un Item", MessageBoxButtons.OK, MessageBoxIcon.Information);
            }
        }

        private void button4_Click(object sender, EventArgs e)
        {
            Cliente currentCliente = clienteBindingSource.Current as Cliente;
            if (currentCliente != null)
            {
                DialogResult rpta = MessageBox.Show("¿Seguro que desea eliminar el registro?", "Mensaje", MessageBoxButtons.YesNo, MessageBoxIcon.Information);
                if (rpta == DialogResult.Yes)
                {
                    clienteBL.RemoveCliente(currentCliente.Id);
                    // MessageBox.Show("Eliminacion Correcta", "Mensaje", MessageBoxButtons.OK, MessageBoxIcon.Information);
                    clienteBindingSource.DataSource = clienteBL.GetAllFromClientes();
                }
            }
            else
            {
                MessageBox.Show("Seleccione un Item", "Mensaje", MessageBoxButtons.OK, MessageBoxIcon.Information);

            }
        }

        private void button1_Click(object sender, EventArgs e)
        {
            if (rbRuc.Checked)
                clienteBindingSource.DataSource = clienteBL.GetFromClienteByRuc(textBox1.Text);

            else
                if (rbNombre.Checked)
                    clienteBindingSource.DataSource = clienteBL.GetFromClienteByNombres(textBox1.Text);                
        
        }
    }
}
